package com.bahiaapk.customize;

import java.util.List;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import com.bahiaapk.R;
import com.bahiaapk.dto.Match;

public class MatchListAdapter extends BaseAdapter {
    
	private Context context;

    private List<Match> listMatch;
   
    public MatchListAdapter (Context context, List<Match> listMatch){
        this.context = context;
        this.listMatch = listMatch;
    }
    
	public int getCount() {
		// TODO Auto-generated method stub
		return  listMatch.size();
	}

	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return listMatch.get(position);
	}

	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	public View getView(int position, View convertView, ViewGroup parent) {
        // Get actual object
		Match match = listMatch.get(position);
		 // on View
        LayoutInflater inflater = (LayoutInflater)
            context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View view = inflater.inflate(R.layout.item_list_match , null);
        
        ImageView flagHomeTeamTMG = (ImageView) view.findViewById(R.id.flagHomeTeamTMG);
        if(match.getHomeTeam() !=null){
        	 if(match.getHomeTeam().getName().equals("Bahia")){
        		 flagHomeTeamTMG.setImageResource(R.drawable.bahia);
        	 }
        }
        TextView nameHomeTeamTX = (TextView)view.findViewById(R.id.nameHomeTeamTX);
        if(match.getHomeTeam() !=null)
        	nameHomeTeamTX.setText(match.getHomeTeam().getName());
        
        ImageView flagAwayTeamIMG = (ImageView) view.findViewById(R.id.flagAwayTeamIMG);
        if(match.getAwayTeam() !=null){
       	 if(match.getAwayTeam().getName().equals("Palmeiras")){
       		 flagAwayTeamIMG.setImageResource(R.drawable.palmeiras);
       	 }
        }
        TextView nameAwayTeamTX = (TextView)view.findViewById(R.id.nameAwayTeamTX);
        if(match.getAwayTeam() !=null)
        	nameAwayTeamTX.setText(match.getAwayTeam().getName());
        
        ImageView score1IMG = (ImageView) view.findViewById(R.id.score1IMG);
        ImageView score2IMG = (ImageView) view.findViewById(R.id.score2IMG);
        if(match.getHomeGoals()==0){
    		score1IMG.setImageResource(R.drawable.score_0);
    	}else if(match.getHomeGoals()==1){
    		score1IMG.setImageResource(R.drawable.score_1);
    	}else if(match.getHomeGoals()==2){
    		score1IMG.setImageResource(R.drawable.score_2);
    	}else if(match.getHomeGoals()==3){
    		score1IMG.setImageResource(R.drawable.score_3);
    	}else if(match.getHomeGoals()==4){
    		score1IMG.setImageResource(R.drawable.score_4);
    	}else if(match.getHomeGoals()==5){
    		score1IMG.setImageResource(R.drawable.score_5);
    	}else if(match.getHomeGoals()==6){
    		score1IMG.setImageResource(R.drawable.score_6);
    	}else if(match.getHomeGoals()==7){
    		score1IMG.setImageResource(R.drawable.score_7);
    	}else if(match.getHomeGoals()==8){
    		score1IMG.setImageResource(R.drawable.score_8);
    	}else if(match.getHomeGoals()==9){
    		score1IMG.setImageResource(R.drawable.score_9);
    	}
    	
    	if(match.getAwayGoals()==0){
    		score2IMG.setImageResource(R.drawable.score_0);
    	}else if(match.getAwayGoals()==1){
    		score2IMG.setImageResource(R.drawable.score_1);
    	}else if(match.getAwayGoals()==2){
    		score2IMG.setImageResource(R.drawable.score_2);
    	}else if(match.getAwayGoals()==3){
    		score2IMG.setImageResource(R.drawable.score_3);
    	}else if(match.getAwayGoals()==4){
    		score2IMG.setImageResource(R.drawable.score_4);
    	}else if(match.getAwayGoals()==5){
    		score2IMG.setImageResource(R.drawable.score_5);
    	}else if(match.getAwayGoals()==6){
    		score2IMG.setImageResource(R.drawable.score_6);
    	}else if(match.getAwayGoals()==7){
    		score2IMG.setImageResource(R.drawable.score_7);
    	}else if(match.getAwayGoals()==8){
    		score2IMG.setImageResource(R.drawable.score_8);
    	}else if(match.getAwayGoals()==9){
    		score2IMG.setImageResource(R.drawable.score_9);
    	}
    	
        TextView stadiumTX = (TextView)view.findViewById(R.id.stadiumTX);
        if(match.getStadium() !=null)
        	stadiumTX.setText(match.getStadium().getName());
        
        TextView informationTX = (TextView)view.findViewById(R.id.informationTX);
        if(match.getDate() !=null && match.getChampionship() !=null)
        	informationTX.setText(match.getDateFormat()+" - "+match.getChampionship().getName());
    	
        return view;
	}

	
	 
	
	

}
